#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "message.h"
#include <QPushButton>

Message *pMsg = nullptr;

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent), ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    setFixedSize(1366, 768);
    ui->centralwidget->setStyleSheet("QWidget{background-color:white;}");
    pMsg = new Message(this);
    pMsg->SetDuration(3000);

    /* 通过全局函数调用 */
    Message::success(this, QString("成功"));
    Message::error(this, QString("错误"));
    Message::warning(this, QString("警告"));
    Message::information(this, QString("信息"));

    QPushButton *pBtn1 = new QPushButton("成功", this);
    QPushButton *pBtn2 = new QPushButton("错误", this);
    QPushButton *pBtn3 = new QPushButton("警告", this);
    QPushButton *pBtn4 = new QPushButton("信息", this);

    connect(pBtn1, &QPushButton::clicked, this, [&]()
            { pMsg->Push(MessageType::MESSAGE_TYPE_SUCCESS, QString("成功")); });

    connect(pBtn2, &QPushButton::clicked, this, [&]()
            { pMsg->Push(MessageType::MESSAGE_TYPE_ERROR, QString("错误")); });

    connect(pBtn3, &QPushButton::clicked, this, [&]()
            { pMsg->Push(MessageType::MESSAGE_TYPE_WARNING, QString("警告")); });

    connect(pBtn4, &QPushButton::clicked, this, [&]()
            { pMsg->Push(MessageType::MESSAGE_TYPE_INFORMATION, QString("信息")); });

    int cnt = 0;
    for (auto &&btn : findChildren<QPushButton *>())
    {
        btn->setCursor(QCursor(Qt::PointingHandCursor));
        btn->setFixedSize(60, 40);
        btn->move(50 + cnt++ * 90, 500);
    }
}

MainWindow::~MainWindow()
{
    delete ui;
}
